//
//  WXDataBase.m
//  CallPolice
//
//  Created by mac on 2017/12/6.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "WXDataBase.h"
@implementation WXDataBase
WXDataBase *database = nil;
+ (instancetype)ShareDataBaseInstance{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        NSString *sqlitePath = [cachePath stringByAppendingPathComponent:@"model.sqlite"];
        database = [[WXDataBase alloc] initWithPath:sqlitePath];
    });
    return database;
}
- (BOOL)creatTableModelIndexofName:(NSString*)name andClass:(Class<WCTTableCoding>)cls{
    BOOL result = [database createTableAndIndexesOfName:name
                                              withClass:cls.class];
    return result;
}
- (BOOL)insertAModelWithModelName:(WCTObject *)model intoTableName:(NSString *)tableName{
    BOOL result = [database insertObject:model into:tableName];
    return result;
}
- (BOOL)deleteObjectFromTableName:(NSString *)name{
    BOOL result = [database deleteAllObjectsFromTable:name];
    return result;
}

@end
